<!DOCTYPE html>
<html>
<head lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <title>活动详情</title>
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css" rel="stylesheet" type="text/css">
    <link href="{$Think.config.RESOURCEURL}wx_assets/freebuy/freebuy.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}"></script>
    <style>
        body{background-color:#EBEBEB;}
    </style>
</head>
<body>
<div class="freeBuyDetail">
    <div class="top">
        <div class="title">我要代言</div>
        <div class="circle">
            <div class="pie_left"><div class="left"></div></div>
            <div class="pie_right"><div class="right"></div></div>
            <div class="mask over">
                <div class="person">已支持的好友</div>
                <div><span>{$friendCount}</span>人</div>
            </div>
            <div class="point"><span></span></div>
        </div>
        <if condition="$status eq 'delivered' OR $status eq 'delivering' OR $status eq 'ok'">
            <div class="cutDown">已完成订单</div>
            <elseif condition="$status eq 'refund' or $status eq 'refundedpart'" />
            <div class="cutDown">已放弃该订单</div>
            <else/>
            <div class="cutDown">已支持的好友{$friendCount}人，还需{$getCount}人</div>
        </if>
    </div>
    <ul class="menu">
        <li>
            <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=freebuy&method=getFriend&params=%7B"oid"%3A"{$oid}"%7D'>已支持的好友</a>
        </li>
        <li>
            <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&force=1&module=product&method=getOrderDetail&params=%7B"tplid":1,"id":{$oid}%7D'>订单详情</a>
        </li>
        <li>
            <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&force=1&module=freebuy&method=getRule&params=%7B"tplid":1,"oid":{$oid}%7D'>活动规则</a>
        </li>
    </ul>
    <if condition="$status eq 'paypart'">
        <div class="footer">
            <a class="friend"
               href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=freebuy&method=getQrCode&params=%7B"oid"%3A"{$oid}"%7D'>找好友支持你</a>
            <div class="twobtn">
                <a id="refundBtn">退款</a>
                <a id="payBtn">补{$chPrice}元购买</a>
            </div>
        </div>
    </if>
</div>
</body>
<script>
var baseUrl = '{$Think.config.SERVER_HOST}';
var viewPage = {
    init:function(){
        var me=this;
        me._initBar();
        me._initEvent();
    },
    _initEvent:function(){
        var me = this;
        $("#payBtn").click(function(){
            me._payOrder();
        });
        $("#refundBtn").click(function(){
            $.util.ok("不玩啦？确定退款吗?",function(){
                me._refundBtn();
            });
        });
    },
    _refundBtn:function(){
        $.util.pageLoading.show("提交中...");
        $.req.get("call.json?module=freebuy&customerId={$customerId}&method=refundOrder",{
            userName:"{$userName}",
            params:{
                "id":"{$oid}"
            }
        },function(data){
            $.util.pageLoading.hide();
            if(data && !data.code){
               location.href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=freebuy&method=getView&params=%7B"oid"%3A"{$oid}"%7D'
            } else {
                $.util.alert(data.msg);
            }
        });
    },
    _payOrder: function() {
        this.WxPayParamAjax(0, '订单{$serialNumber}补差价购买',{$chPrice}, 'freebuy', {$oid}, 0, "{$userName}", 'supplementAmount');
    },
    _initBar:function(){
        var deposit = "{$needPrice}";
        var refue = "{$refueMoney}";
        var status = "{$status}";
        var num =Math.ceil(refue)/Math.ceil(deposit);
        if(num>1||status=='delivered'||status=='delivering'||status=='ok'){
             num = 100*3.6;
        }else{
            num = num*100*3.6;
        }
        var count=0;
        var handle = setInterval(function() {
            if(count<=num){
                if(count<=180){
                    $(".circle").find('.right').css('transform', "rotate(" + count + "deg)");
                    $(".circle").find('.right').css('-webkit-transform', "rotate(" + count + "deg)");
                }else{
                    $(".circle").find('.left').css('transform', "rotate(" + (count-180) + "deg)");
                    $(".circle").find('.left').css('-webkit-transform', "rotate(" + (count-180) + "deg)");
                }
                $(".circle").find('.point').css('transform', "rotate(" + (count)+ "deg)");
                $(".circle").find('.point').css('-webkit-transform', "rotate(" + (count)+ "deg)");
                count+=10;
            }else{
                clearInterval(handle);
            }
        },30)
    },
    /*
     * 获取微信支付参数
     * sn:订单id
     * desc:商品描述显示在微信支付界面中
     * productFee:产品价格
     * module:回调模块
     * moduleId:回调模块id
     * transportFee:运费单位分
     * userName:用户openid
     * method:回调方法
     */
    WxPayParamAjax: function(sn, desc, productFee, module, moduleId, transportFee, userName, method) {
        var urlString = baseUrl + 'Wxpay/getWxPayParam.json?customerId={$customerId}';
        var me = this;
        $.util.pageLoading.show("提交中...");
        $.ajax({
            url: urlString,
            dataType: "json",
            type: "post",
            data: {
                'sn': sn,
                'desc': desc,
                'productFee': productFee,
                'module': module,
                'moduleId': moduleId,
                'transportFee': transportFee,
                'userName': userName,
                'method': method
            },
            success: function(d) {
                $.util.pageLoading.hide();
                if (d.code) {
                    $.util.alert(d.msg);
                    return;
                }
                WeixinJSBridge.invoke('getBrandWCPayRequest', d.pkg, function(res) {
                    WeixinJSBridge.log(res.err_msg);
                    if (res.err_msg == 'get_brand_wcpay_request:ok') {
                        location.href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=freebuy&method=getView&params=%7B"oid"%3A"{$oid}"%7D';
                    } else {
                        var res = res;
                        if (res.err_msg == 'get_brand_wcpay_request:cancel') {
                            return alert("操作已取消"), void 0
                        } else if (res.err_msg == 'get_brand_wcpay_request:fail') {
                            return alert("网络错误发送失败，请稍后再试"), void 0
                        } else if (res.err_msg == 'access_control:not_allow' || res.err_msg == 'system:access_denied') {
                            return alert("商家尚未开通微信支付"), void 0
                        } else {
                            return alert(res.err_msg), void 0
                        }
                    }
                });
            }
        });
    },
    getShareUrl:function(){
        var shareUrl="";
        var me=this;
        var params={
            "oid":"{$id}",
            "qId":"{$qId}",
            "miUId":"{$miUid}"
        };
        params=encodeURIComponent(JSON.stringify(params));
        shareUrl=baseUrl+'call.html?customerId={$customerId}&module=freebuy&method=getQrCode&params='+params;
        return shareUrl;
    }
};
viewPage.init();
var shareUrl=viewPage.getShareUrl();
wx_share.init({
    "title":'{$productList.title}',
    "desc":"{$productList.recommend}",
    "link":shareUrl,
    "imgUrl":"{$headimgurl}",
    "pkg":{
        "appId": '{$pkg.appId}',
        "timestamp": {$pkg.timestamp},
        "nonceStr": '{$pkg.nonceStr}',
        "signature": '{$pkg.signature}'
    },
    success:function(config,shareType){

    }
});
</script>

</html>
